package bean;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

public class TranslateActionForm {
	
	@SuppressWarnings("unchecked")
	public static ActionForm formatFrom(HttpServletRequest request, String classUrl){
		ActionForm af = null;
		try {
			Class clazz = Class.forName(classUrl);
			af = (ActionForm)clazz.newInstance();
			Field[] fields = clazz.getDeclaredFields();
			for(Field f : fields){
				f.setAccessible(true);
				f.set(af, request.getParameter(f.getName()));
				f.setAccessible(false);
				
			}
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		
		return af;
		
	}

}
